package cn.tedu.boot22.controller;

import cn.tedu.boot22.entity.User;
import cn.tedu.boot22.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wxd
 * @version 1.0
 */
@Controller
public class UserController {
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/reg")
    @ResponseBody
    public String reg(User user) {
        System.out.println("user = " + user);
        userMapper.insert(user);
        return user.toString();
    }

    @RequestMapping("/deleteUser")
    @ResponseBody
    public String deleteUser(String username) {
        userMapper.deleteByName(username);
        return "成功删除";
    }

    @RequestMapping("/updateUser")
    @ResponseBody
    public String updateUser(User user) {
        userMapper.update(user);
        return "修改成功";
    }

    @RequestMapping("/queryUser")
    @ResponseBody
    public String queryUser() {
        return userMapper.select().toString();
    }
}
